package com.tiantian.quanminxiu.presenter;

import android.util.Log;

import com.shenglian.utils.utils.CommonUtils;
import com.tiantian.quanminxiu.api.AnchorService;
import com.tiantian.quanminxiu.utils.ApplicationBase;
import com.tiantian.quanminxiu.utils.Constants;
import com.tiantian.quanminxiu.utils.UserData;
import com.tiantian.quanminxiu.view.MainAttentionView;

import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by admin on 2016/8/11.
 */
public class MainAttentionPresent implements Presenter<MainAttentionView> {

    private MainAttentionView mainAttentionView;

    @Override
    public void attachView(MainAttentionView view) {
        this.mainAttentionView = view;
    }

    @Override
    public void detachView() {
        mainAttentionView = null;
    }

    public void initAttentionList(String User_ID,int iDisplayLength){
        mainAttentionView.Loading_Open();
        ApplicationBase app = ApplicationBase.get(mainAttentionView.getContext());
        AnchorService service = app.getAnchorService();
        service.attentionlist(UserData.Current.mid, UserData.Current.sign, Constants.APP_TYPE, User_ID,
                true, true, 0, 0, iDisplayLength,"Live_StartTime")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(app.defaultSubscribeScheduler())
                .finallyDo(()->{
                    mainAttentionView.Loading_Close();
                })
                .subscribe(str -> {
                    Log.i("dd", "-ddinitAttentionList:" + str.toString());
                    mainAttentionView.initAttentionList(str.optJSONObject("data").optJSONArray("aaData"));
                }, throwable -> {
                    CommonUtils.showToask(mainAttentionView.getContext(), throwable.getMessage());
                });

    }

}
